package org.zhenggn.designpattern.chain;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by zhenggn on 2017/5/3.
 */
public class Client {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newCachedThreadPool();

        for (int i = 0; i < 500; i++) {
            executorService.execute(new Runnable() {
                @Override
                public void run() {

                    System.out.println("============"+Thread.currentThread().getName()+"========================= start");

                    Handler h1 = new GeneralManager();
                    Handler h2 = new DeptManager();
                    Handler h3 = new ProjectManager();

                    h1.setSuccessor(h2);

                    h2.setSuccessor(h3);

                    String ret1 = h1.handleFeeRequest("小李", 3000);
                    System.out.println("the ret1=" + ret1);

                    MyThreadLocal.unset();

                    System.out.println("============"+Thread.currentThread().getName()+"========================= end");


                }

            });
        }

        for (int i = 0; i < 500; i++) {
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("------------------------------------"+Thread.currentThread().getName()+"start-------------------------------------------");

                    Handler h1 = new GeneralManager();
                    Handler h2 = new DeptManager();
                    Handler h3 = new ProjectManager();

                    h1.setSuccessor(h2);

                    h2.setSuccessor(h3);

                    String ret1 = h1.handleFeeRequest("小李", 30);
                    System.out.println("the ret1=" + ret1);

                    MyThreadLocal.unset();


                    System.out.println("----------------------------------"+Thread.currentThread().getName()+"---end-----------------------------------------");
                }

            });
        }

    }
}